package org.hdax.dm.rest.service;

import org.hdax.dm.dao.entitydao.UserDao;
import org.hdax.dm.entity.linkuser.LinkUser;
import org.hdax.dm.entity.user.User;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class RestUserService {
    @Autowired
    private UserDao userDao;

    @PostMapping(path = "/findByPhone")
    public User findByPhone(@RequestParam("phone") String phone) {
        return userDao.findByPhone(phone);
    }


    @PostMapping(path = "/InsertUser")
    public void InsertUser(@RequestBody User user) {
        userDao.save(user);
    }

    @PostMapping(path = "/modifyUserInfo")
    public void modifyUserInfo(@RequestBody User user) {
        User user1 = userDao.findByPhone(user.getPhone());
        if (user1 != null) {
            BeanUtils.copyProperties(user, user1);
            userDao.save(user1);
        }
    }
}
